
import java.util.List;
import monitoreo.Estadistica;
import monitoreo.Monitoreable;
import monitoreo.Resumen;

/**
 *
 * @author Osvaldo Clua
 * @author Esteban Czelada
 */
public abstract class Tarea extends Monitoreable implements Runnable {

    long id;  // Java Thread id
    String soy = "";  // rol
    String yo; // Java Thread name
//    List lista;
    Resumen resumen;
    boolean debug;
 
    Tarea(String indice, Estadistica est, Resumen resumen, boolean debug) { //, List li) {
        super(indice, est);
        this.resumen = resumen;
//        lista = li;
        this.debug = debug;
    }

    abstract public void loop();
    
    @Override
    public void run() {
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        yo = Thread.currentThread().getName();
        id = Thread.currentThread().getId();
        getEst().setNombre(soy + " " + yo + " (tid=" + id + ")");

        loop();
        
        if (debug)
            System.out.println("Terminada " + getEst());

        synchronized(resumen) {
            resumen.actualizar(getEst().getT());
        }
 //       lista.add(getEst().getT());
   }
}
